from Goldenberry.optimization.ga.GbMutatorMgr.MutatorStrategy import MutatorStrategy
from Goldenberry.statistics.distributions import GaussianTrunc
import numpy as np
import random as ran

class TruncateGaussMutation(MutatorStrategy):
    """Truncate Gauss Muation."""
    def mutate(self, individual,prob):
        """Mutate a individual using multiple point bit mutation.
    
         :param individual: GbIndividual to mutate
         :returns: array genotype of the individual generated
         """
        dist = GaussianTrunc(means = np.tile(np.mean(individual.genotype), 1), stdevs = np.std(individual.genotype), low = np.amin(individual.genotype), high = np.amax(individual.genotype))
        genotype = individual.genotype
        size = genotype.shape[0]
        #probability = 1.0 / size
        probability = prob
        for x in range(len(genotype)):
            random = ran.random()
            if probability > random:
               genotype[x] = dist.sample(1)[0]
        return individual